package self.niu.com.handle;

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private int[] images = {R.mipmap.sc, R.mipmap.sz, R.mipmap.cq};
    private ImageView imageView;
    private TextView tv ;
    private TextView tv1 ;
    private MyThread myThread = new MyThread();
    private th myth = new th();
    private int index;
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            tv.setText(msg.arg1 + "");
            tv1.setText(msg.arg2 + "sssss");
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        imageView = (ImageView) findViewById(R.id.image);
        tv = (TextView) findViewById(R.id.tv);
        tv1 = (TextView) findViewById(R.id.tv2);

        handler.postDelayed(myth, 2000);
        handler.postDelayed(myThread, 2000);
       /* new Thread(){
            @Override
            public void run() {
                super.run();
            }
        }.start();*/
    }
    class th implements  Runnable{

        @Override
        public void run() {
            index++;
            Message message = handler.obtainMessage();
            message.arg2 = 1000+index;
            handler.sendMessage(message);
            handler.postDelayed(myth, 2000);
        }
    }
    class MyThread implements Runnable {
        @Override
        public void run() {
            index++;
            Message message = handler.obtainMessage();
            message.arg1 = 100+index;
            handler.sendMessage(message);
          /*  index = index % images.length;
            imageView.setImageResource(images[index]);*/
            handler.postDelayed(myThread, 2000);
        }
    }
}
